$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/buserinfo/referrerInfo',
        datatype: "json",
		async:false,
		colModel: [
			{ label: '用户ID', name: 'userId', index: 'user_id',align: "center", width: 60,
				formatter:function(value,options,rowData){
					return "<a  onclick='window.open(\"../sys/buserinfo.html?userId="+value+"\")'>"+value+"</a>";
				}
			},
			{ label: '用户名称', name: 'nickName', index: 'nick_name',align: "center", width: 80 },
			{ label: '关注品牌', name: 'brandName', index: 'brandName',align: "center", width: 100 },
			{ label: '推荐人数', name: 'refererTotal', index: 'refererTotal',align: "center", width: 80 },
			{ label: '目前关注数', name: 'concernTotal', index: 'concernTotal',align: "center", width: 80 },
            { label: '公众号', name: 'gzhName', index: 'gzh_code',align: "center", width:80 }
        ],
		viewrecords: true,
		height: "100%",
		rowNum: 15,
		rowList : [15,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
		postData:{"userId": vm.q.userId, "userName": vm.q.userName, "gzhCode": vm.q.gzhCode, "beginDate": vm.q.beginDate, "endDate": vm.q.endDate},
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });

	$.ajax({
		type: "POST",
		async:false,
		url: baseURL + 'sys/buserinfo/getUserGzhList',
		contentType: "application/json",
		success: function(r){
			if(r.code==0){
				//vm.bbrandinfo=r.brandInfo;
				$("#selectUserGzhList").append(
					"<option value=''>全部平台</option>");
				for(var i=0;i<r.userGzhList.length;i++){
					$("#selectUserGzhList").append(
						"<option value=" + r.userGzhList[i].gzhCode +">"+ r.userGzhList[i].gzhName+"</option>");
				}
			}
		}
	});
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			userId:null,
			userName: null,
			gzhCode:"",
			beginDate:null,
			endDate:null
		},
		showList: true,
	},
	mounted() {
		let now = new Date();

		let y = now.getFullYear(); //年
        let m = now.getMonth() + 1 + ''; //月

        m = m.length == 1 ? '0' + m : m;
        this.q.beginDate = y + '-' + m + '-01';
        //本月的结束时间
        let monthEndDate = new Date(y, now.getMonth()+1, 0);
        this.q.endDate = y + '-' + m + '-' + monthEndDate.getDate();
	},
	methods: {
		query: function () {
			// 参数校验
			if (vm.q.beginDate && vm.q.endDate) {
				if (new Date(vm.q.beginDate) > new Date(vm.q.endDate)) {
					alert("开始日期不能大于结束日期");
					return;
				}
			}

            vm.showList = true;
            $("#jqGrid").jqGrid('setGridParam',{
				postData:{"userId": vm.q.userId, "userName": vm.q.userName, "gzhCode": vm.q.gzhCode, "beginDate": vm.q.beginDate, "endDate": vm.q.endDate},
                page:1
            }).trigger("reloadGrid");
		},
		reload: function (event) {
			debugger;
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
				postData:{"userId": vm.q.userId, "userName": vm.q.userName, "gzhCode": vm.q.gzhCode, "beginDate": vm.q.beginDate, "endDate": vm.q.endDate},
                page:page
            }).trigger("reloadGrid");
		}
	}
});
